package com.qipay.mapper;


import com.qipay.baas.model.CpInfo;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;
import java.util.Map;

@Mapper
public interface CpInfoMapper extends com.qipay.baas.mapper.CpInfoMapper {

    @SelectProvider(type=CpInfoSqlProvider.class, method="selectByCondition")
    @Results({
            @Result(column="cp_id", property="cpId", jdbcType=JdbcType.BIGINT, id=true),
            @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
            @Result(column="legal_person", property="legalPerson", jdbcType=JdbcType.VARCHAR),
            @Result(column="legal_person_idcard1", property="legalPersonIdcard1", jdbcType=JdbcType.VARCHAR),
            @Result(column="legal_person_idcard2", property="legalPersonIdcard2", jdbcType=JdbcType.VARCHAR),
            @Result(column="business_license_no", property="businessLicenseNo", jdbcType=JdbcType.VARCHAR),
            @Result(column="business_license_pic", property="businessLicensePic", jdbcType=JdbcType.VARCHAR),
            @Result(column="org_code_license", property="orgCodeLicense", jdbcType=JdbcType.VARCHAR),
            @Result(column="mail", property="mail", jdbcType=JdbcType.VARCHAR),
            @Result(column="addr", property="addr", jdbcType=JdbcType.VARCHAR),
            @Result(column="url", property="url", jdbcType=JdbcType.VARCHAR),
            @Result(column="industry", property="industry", jdbcType=JdbcType.VARCHAR),
            @Result(column="contacts", property="contacts", jdbcType=JdbcType.VARCHAR),
            @Result(column="contacts_tel", property="contactsTel", jdbcType=JdbcType.VARCHAR),
            @Result(column="contacts_mobile", property="contactsMobile", jdbcType=JdbcType.VARCHAR)
    })
    List<CpInfo> selectByCondition(Map<String, Object> params);

    @SelectProvider(type=CpInfoSqlProvider.class, method="countByCondition")
    long countByCondition(Map<String, Object> params);

    @SelectProvider(type=CpInfoSqlProvider.class, method="selectByAgentId")
    @Results({
            @Result(column="cp_id", property="cpId", jdbcType=JdbcType.BIGINT, id=true),
            @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
            @Result(column="legal_person", property="legalPerson", jdbcType=JdbcType.VARCHAR),
            @Result(column="legal_person_idcard1", property="legalPersonIdcard1", jdbcType=JdbcType.VARCHAR),
            @Result(column="legal_person_idcard2", property="legalPersonIdcard2", jdbcType=JdbcType.VARCHAR),
            @Result(column="business_license_no", property="businessLicenseNo", jdbcType=JdbcType.VARCHAR),
            @Result(column="business_license_pic", property="businessLicensePic", jdbcType=JdbcType.VARCHAR),
            @Result(column="org_code_license", property="orgCodeLicense", jdbcType=JdbcType.VARCHAR),
            @Result(column="mail", property="mail", jdbcType=JdbcType.VARCHAR),
            @Result(column="addr", property="addr", jdbcType=JdbcType.VARCHAR),
            @Result(column="url", property="url", jdbcType=JdbcType.VARCHAR),
            @Result(column="industry", property="industry", jdbcType=JdbcType.VARCHAR),
            @Result(column="contacts", property="contacts", jdbcType=JdbcType.VARCHAR),
            @Result(column="contacts_tel", property="contactsTel", jdbcType=JdbcType.VARCHAR),
            @Result(column="contacts_mobile", property="contactsMobile", jdbcType=JdbcType.VARCHAR)
    })
    List<CpInfo> selectByAgentId(Map<String, Object> params);

    @SelectProvider(type=CpInfoSqlProvider.class, method="countByAgentId")
    long countByAgentId(Map<String, Object> params);

    @Select({
            "select ci.* from cp c inner join cp_info ci on c.id= ci.cp_id where c.account_state= 2 order by c.agent_id asc, c.id asc "
    })
    @Results({
            @Result(column="cp_id", property="cpId", jdbcType=JdbcType.BIGINT, id=true),
            @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
            @Result(column="legal_person", property="legalPerson", jdbcType=JdbcType.VARCHAR),
            @Result(column="legal_person_idcard1", property="legalPersonIdcard1", jdbcType=JdbcType.VARCHAR),
            @Result(column="legal_person_idcard2", property="legalPersonIdcard2", jdbcType=JdbcType.VARCHAR),
            @Result(column="business_license_no", property="businessLicenseNo", jdbcType=JdbcType.VARCHAR),
            @Result(column="business_license_pic", property="businessLicensePic", jdbcType=JdbcType.VARCHAR),
            @Result(column="org_code_license", property="orgCodeLicense", jdbcType=JdbcType.VARCHAR),
            @Result(column="mail", property="mail", jdbcType=JdbcType.VARCHAR),
            @Result(column="addr", property="addr", jdbcType=JdbcType.VARCHAR),
            @Result(column="url", property="url", jdbcType=JdbcType.VARCHAR),
            @Result(column="industry", property="industry", jdbcType=JdbcType.VARCHAR),
            @Result(column="contacts", property="contacts", jdbcType=JdbcType.VARCHAR),
            @Result(column="contacts_tel", property="contactsTel", jdbcType=JdbcType.VARCHAR),
            @Result(column="contacts_mobile", property="contactsMobile", jdbcType=JdbcType.VARCHAR)
    })
    List<CpInfo> listAll();

    @Select({
            "select ci.* from cp c inner join cp_info ci on c.id= ci.cp_id where c.account_state= 2 and c.type=#{type} order by c.agent_id asc, c.id asc "
    })
    @Results({
            @Result(column="cp_id", property="cpId", jdbcType=JdbcType.BIGINT, id=true),
            @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
            @Result(column="legal_person", property="legalPerson", jdbcType=JdbcType.VARCHAR),
            @Result(column="legal_person_idcard1", property="legalPersonIdcard1", jdbcType=JdbcType.VARCHAR),
            @Result(column="legal_person_idcard2", property="legalPersonIdcard2", jdbcType=JdbcType.VARCHAR),
            @Result(column="business_license_no", property="businessLicenseNo", jdbcType=JdbcType.VARCHAR),
            @Result(column="business_license_pic", property="businessLicensePic", jdbcType=JdbcType.VARCHAR),
            @Result(column="org_code_license", property="orgCodeLicense", jdbcType=JdbcType.VARCHAR),
            @Result(column="mail", property="mail", jdbcType=JdbcType.VARCHAR),
            @Result(column="addr", property="addr", jdbcType=JdbcType.VARCHAR),
            @Result(column="url", property="url", jdbcType=JdbcType.VARCHAR),
            @Result(column="industry", property="industry", jdbcType=JdbcType.VARCHAR),
            @Result(column="contacts", property="contacts", jdbcType=JdbcType.VARCHAR),
            @Result(column="contacts_tel", property="contactsTel", jdbcType=JdbcType.VARCHAR),
            @Result(column="contacts_mobile", property="contactsMobile", jdbcType=JdbcType.VARCHAR)
    })
    List<CpInfo> listByCpType(@Param("type")byte type);




    @Select({
            "select ci.* from cp c inner join cp_info ci on c.id= ci.cp_id where c.agent_id= #{agentId} and c.account_state= 2 order by c.agent_id asc, c.id asc "
    })
    @Results({
            @Result(column="cp_id", property="cpId", jdbcType=JdbcType.BIGINT, id=true),
            @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
            @Result(column="legal_person", property="legalPerson", jdbcType=JdbcType.VARCHAR),
            @Result(column="legal_person_idcard1", property="legalPersonIdcard1", jdbcType=JdbcType.VARCHAR),
            @Result(column="legal_person_idcard2", property="legalPersonIdcard2", jdbcType=JdbcType.VARCHAR),
            @Result(column="business_license_no", property="businessLicenseNo", jdbcType=JdbcType.VARCHAR),
            @Result(column="business_license_pic", property="businessLicensePic", jdbcType=JdbcType.VARCHAR),
            @Result(column="org_code_license", property="orgCodeLicense", jdbcType=JdbcType.VARCHAR),
            @Result(column="mail", property="mail", jdbcType=JdbcType.VARCHAR),
            @Result(column="addr", property="addr", jdbcType=JdbcType.VARCHAR),
            @Result(column="url", property="url", jdbcType=JdbcType.VARCHAR),
            @Result(column="industry", property="industry", jdbcType=JdbcType.VARCHAR),
            @Result(column="contacts", property="contacts", jdbcType=JdbcType.VARCHAR),
            @Result(column="contacts_tel", property="contactsTel", jdbcType=JdbcType.VARCHAR),
            @Result(column="contacts_mobile", property="contactsMobile", jdbcType=JdbcType.VARCHAR)
    })
    List<CpInfo> listByAgentId(@Param("agentId") Long agentId);
}